<?php include_once "top.php";
$user=$db->ig2_want('mae_user','id='.$_GET['id'].' and is_delete=0');
//if(!$user) tellgoto('','user.php');
$role=$db->ig2_want('mae_role','uid='.$user['id'].' and is_delete=0');
//if (!$role) tellgoto('','user.php');
$shop=$db->ig2_want('mae_shop','id='.$role['shop_id']);
if($user['score']>=6000) $mark=3;
else if($user['score']>=2500 && $user['score']<=5999) $mark=2;
else if($user['score']<=2499) $mark=1;

// 取得上月增长率
$nowtime=date('Y-m-01', strtotime(date("Y-m-d")));//当月开始时间 Y-m-d格式
$currentYear = date('Y', strtotime($nowtime));
$growthRate = $db->ig2_want('mae_growth_rate', 'shopid = '.$shop['id'].' AND statyear = "'.$currentYear.'"');

?>
<link href="css/discount.css" rel="stylesheet" type="text/css" />
<link href="css/common.css" rel="stylesheet" type="text/css" />
<input type="hidden" id="shopid" value="<?php echo($shop['id']);?>" />
<input type="hidden" id="userid" value="<?php echo($user['id']);?>" />
<div class="container">
	<div id="loadings" class="posit99"></div>
	<div class="p4">
		<span class="xm" id="p4text_1"><?php echo $user['name']?></span>
		<span class="dz" id="p4text_2">喜力大师<?php 
		switch($mark){
			case 1 : echo '一'; break;
			case 2 : echo '二'; break;
			case 3 : echo '三'; break;
		}
		?>级</span>
		<img class="p4bg bg" src="images/p4bg.jpg">
		<?php if($_GET['source']=='user'){?>
		<img class="bt" id="p4_3" src="images/p2_3.png">
		<?php }?>
		<div id="p4box">
			<img class="p1bg bg" src="images/p2boxbg.png">
			<img id="p4boxbt" src="images/p2boxbt.jpg">
            <script>
				document.getElementById("p4boxbt").addEventListener("touchstart", touchStartp4boxbt, false);
				document.getElementById("p4boxbt").addEventListener("touchend", touchEndp4boxbt, false);
				function touchStartp4boxbt(event){
					startX = event.touches[0].clientX;
					document.getElementById('p4boxbt').src='images/p2boxbg_h.jpg';	
				}
				function touchEndp4boxbt(event){
					endX = event.changedTouches[0].clientX;
					document.getElementById('p4boxbt').src='images/p2boxbg.jpg';
				}	
			</script>
            <img id="p4boxbt_2" src="images/p2boxbt_2.jpg">
            <script>
				document.getElementById("p4boxbt_2").addEventListener("touchstart", touchStartp4boxbt_2, false);
				document.getElementById("p4boxbt_2").addEventListener("touchend", touchEndp4boxbt_2, false);
				function touchStartp4boxbt_2(event){
					startX = event.touches[0].clientX;
					document.getElementById('p4boxbt_2').src='images/p2boxbg_2_h.jpg';	
				}
				function touchEndp4boxbt_2(event){
					endX = event.changedTouches[0].clientX;
					document.getElementById('p4boxbt_2').src='images/p2boxbg_2.jpg';
				}	
			</script>
			<input class="ipt" id="nm" type="text" name="" value="<?php echo $user['name']?>">
			<input class="ipt" id="tel" type="text" name="" value="<?php echo $user['phone']?>">
			<input class="ipt" id="add" type="text" name="" value="<?php echo $user['address']?>">
			<span class="ipt" id="shop_name"><?php echo $shop['name']?></span>
		</div>
		<img class="bt oil" id="oil_1" src="images/oil_2.png">
		<img class="bt oil" id="oil_2" src="images/oil_<?php echo $mark>1?'2':'1'?>.png">
		<img class="bt oil" id="oil_3" src="images/oil_<?php echo $mark>2?'2':'1'?>.png">
		<img class="bt" id="p4_1" src="images/p4_1.png">
		<?php if($_GET['source']=='user'){?>
		<img class="bt" id="p4_2" src="images/p4_2.png">
		<!--<img class="bt" id="close" src="images/close.png" onclick="wx.closeWindow()">-->
		<?php }?>
		<div id="rule">
			<img id="p4_2mb" src="images/p4_2mb.png">
			<img id="rule_1" src="images/rule_1.jpg">
            <script>
				document.getElementById("rule_1").addEventListener("touchstart", touchStartrule_1, false);
				document.getElementById("rule_1").addEventListener("touchend", touchEndrule_1, false);
				function touchStartrule_1(event){
					startX = event.touches[0].clientX;
					document.getElementById('rule_1').src='images/rule_1_h.jpg';	
				}
				function touchEndrule_1(event){
					endX = event.changedTouches[0].clientX;
					document.getElementById('rule_1').src='images/rule_1.jpg';
				}	
			</script>
			<!--<label class="p2text" id="ruletext_1">兑换规则兑换规则兑换兑换规则兑换规则兑换兑换规则兑换兑换规则兑换兑换规则</label>
			<label class="p2text" id="ruletext_2">兑换规则兑换规则兑换兑换规则兑换规则兑换兑换规则兑换兑换规则兑换兑换规则</label>-->
		</div>
		<span id="p4text_3"><?php 
		switch($mark){
			case 1 : echo $user['score'].'/2499'; break;
			case 2 : echo $user['score'].'/5999'; break;
			case 3 : echo $user['score'].'/*'; break;
		}
		?></span>
		<img class="bt p4bt" id="p4bt_1" src="images/p4bt_1.png"<?php echo $_GET['source']=='user'?' onclick="location.href=\'shop.php?id='.$user['id'].'\'"':''?>>
		<img class="bt p4bt" id="p4bt_2" src="images/p4bt_2.png"<?php echo $_GET['source']=='user'?' onclick="location.href=\'answer.php?id='.$user['id'].'\'"':''?>>
		<img class="bt p4bt" id="p4bt_3" src="images/p4bt_3.png"<?php echo $_GET['source']=='user'?' onclick="$(\'#integral\').fadeIn(500)"':''?>>
		<label id="p4bt_4"><?php $score=$user['score']-$user['used_score'];echo $score?></label>
		<div id="integral">
			<img id="p4bt_3mb" src="images/p4bt_3mb.png">
			<img id="integral_1" src="images/rule_1.jpg">
            <script>
				document.getElementById("integral_1").addEventListener("touchstart", touchStartintegral_1, false);
				document.getElementById("integral_1").addEventListener("touchend", touchEndintegral_1, false);
				function touchStartintegral_1(event){
					startX = event.touches[0].clientX;
					document.getElementById('integral_1').src='images/rule_1_h.jpg';	
				}
				function touchEndintegral_1(event){
					endX = event.changedTouches[0].clientX;
					document.getElementById('integral_1').src='images/rule_1.jpg';
				}	
			</script>
			<!--<label class="p2text" id="integraltext_1">兑换规则兑换规则兑换兑换规则兑换规则兑换兑换规则兑换兑换规则兑换兑换规则</label>
			<label class="p2text" id="integraltext_2">兑换规则兑换规则兑换兑换规则兑换规则兑换兑换规则兑换兑换规则兑换兑换规则</label>-->
		</div>
		<img class="bt" id="sale_1" src="images/sale_1.png">
		<img class="bt" id="change_1" src="images/change_2.png">
		<div id="sale">
			<?php 
			$stime=date('Y-m-01', strtotime(date("Y-m-d")));//当月开始时间 Y-m-d格式
			$etime=strtotime("$stime +1 month");//当月结束时间 时间戳
			$stime=strtotime($stime);//当月开始时间 时间戳
			$sells=$db->ig2_select('mae_sell','uid = "'.$user['id'].'" and create_time >= "'.$stime.'" and create_time < "'.$etime.'"');

            // 本月销售不能把红包兑换算进去
            $c = count($sells);
			
			$sql='
				select * from mae_sell where uid in (
					select uid from mae_role where shop_id in (
						select id from mae_shop where city_id=(
							select city_id from mae_shop where id=(
								select shop_id from mae_role where uid='.$user['id'].' and is_delete=0
							)
						)
					)
				) and create_time >= "'.$stime.'" and create_time < "'.$etime.'"';

			$array=array();
			foreach($db->ig2_query_select($sql) as $value){
				if(array_key_exists($value['uid'],$array)) $array[$value['uid']]+=1;
				else $array[$value['uid']]=1;
			}
			arsort($array);
			$i=1;
			foreach($array as $key=>$val){
				if($key==$_GET['id']) break;
				$i++;
			}

            // 销售记录增加红包领取的记录
            foreach($sells as &$sell) {
                $sell['type'] = 1;
            }

            // 优惠码验证记录追加
            $promocodes = $db->ig2_query_select('SELECT "优惠码验证" as productname, createtime as create_time, 2 as type, score from mae_promocode_exchange_log where userid = "'.$user['id'].'" and createtime >= "'.$stime.'" and createtime < "'.$etime.'"');
            if ($promocodes) {
                if ($sells) {
                    $sells = array_merge($sells, $promocodes);
                } else {
                    $sells = $promocodes;
                }
            }

            // 红包记录追加
            $redPockets = $db->ig2_query_select('SELECT activityname as productname, createtime as create_time, 3 as type, exchangescore as score from mae_red_pocket_exchange_log where userid = "'.$user['id'].'" and createtime >= "'.$stime.'" and createtime < "'.$etime.'"');
            if ($redPockets) {
                if ($sells) {
                    $sells = array_merge($sells, $redPockets);
                } else {
                    $sells = $redPockets;
                }
            }


            // 按创建时间倒序排列
            $keysvalue = $new_array = array();
            foreach ($sells as $k=>$v){
                $keysvalue[$k] = $v['create_time'];
            }
            arsort($keysvalue);

            reset($keysvalue);
            foreach ($keysvalue as $k=>$v){
                $new_array[] = $sells[$k];
            }

            $sells = $new_array;
            ?>
			<span id="p4text_4">本月门店销量达<?php echo($growthRate['purpose'])?>，店长可获额外奖励<?php echo($growthRate['addscore'])?>分</span>
			<img class="bt" id="sale_3" src="images/sale_3_new.png">
			<div id="salebar">
				<?php 
				foreach($sells as $list){
                    $type = $list['type'];
                    $productName = $list['productname'];
                    $dateMd = date('m月d日',$list['create_time']);
                    $score = $list['score'];

                    if ($type == 1 || $type == 2) {
                        $pro=$db->ig2_want('mae_pro','pro_id='.$list['pro_id']);
                        if (!$productName) {
                            $productName = $pro['short_name'];
                        }

                        // 旧记录都是15分
                        if (!$score) {
                            $score = 15;
                        }
                    }
				?>
				<li>
					<span class="saletext saletext_1_new"><?php echo $dateMd?></span>
					<span class="saletext saletext_2_new"><?php echo $productName?></span>
					<span class="saletext saletext_3_new"><?php echo $score?>分</span>
                    <span class="saletext saletext_4_new">
                        <?php
                            if ($type == 2) {
                        ?>
                                <img class="bt" src="images/coupon.png">
                        <?php
                            } else if ($type == 3) {
                        ?>
                                <img class="bt" src="images/redpocket.png">
                        <?php
                            }
                        ?>
                    </span>
				</li>
				<?php }?>
			</div>
		</div>
		<div id="change">
			<?php if($_GET['source']=='user'){?>
       	 	<img class="bt" id="change_7" src="images/change_7.jpg">
			<?php }?>
			<img class="bt" id="change_3" src="images/sale_3_new.png">
			<div id="changebar">
				<?php 
				foreach($db->ig2_select('mae_shop_user_exchange_list','uid='.$user['id'].' order by id desc') as $list){
					$prize=$db->ig2_want('mae_prize','id='.$list['prize_id']);
				?>
				<li>
					<span class="saletext saletext_1"><?php echo date('m月d日',$list['create_time'])?></span>
					<span class="saletext saletext_2"><?php echo $prize['name']?></span>
					<span class="saletext saletext_3"><?php echo $prize['need_integral']?>分</span>	
					<?php if($_GET['source']=='user' && $prize['is_virtual'] == 1){?>
					<img class="bt change_3" id="change_3<?php echo $list['id']?>" src="images/change_3.jpg" onclick="selvirtualinfo(1,<?php echo $list['id']?>)">
                    <script>
						document.getElementById("change_3<?php echo $list['id']?>").addEventListener("touchstart", touchStartchange_3<?php echo $list['id']?>, false);
						document.getElementById("change_3<?php echo $list['id']?>").addEventListener("touchend", touchEndchange_3<?php echo $list['id']?>, false);
						function touchStartchange_3<?php echo $list['id']?>(event){
							startX = event.touches[0].clientX;
							document.getElementById('change_3<?php echo $list['id']?>').src='images/change_3_h.jpg';	
						}
						function touchEndchange_3<?php echo $list['id']?>(event){
							endX = event.changedTouches[0].clientX;
							document.getElementById('change_3<?php echo $list['id']?>').src='images/change_3.jpg';
						}	
					</script>
					<?php }?>
				</li>
				<?php }?>
			</div>
		</div>
        <div id="old">
            <img class="bg" id="oldbg" src="images/oldbg.png">
            <img class="bg" id="old_4" src="images/p2bar_3.png">
            <div id="oldbar">
				<?php foreach($db->ig2_select('mae_award','uid='.$user['id']) as $list){?>
                <li>
                    <label class="bt old_1"><?php echo trim($list['jd_card'])?date('Y年m月d日',$list['end_time']):'2016年2月29日'?></label>
                    <label class="bt old_2"><?php 
					if(trim($list['jd_card'])){
						echo '京东券'.$list['price'].'元抵用券';
					}else{
						echo '哈根达斯券33元';
					}
					?></label>
                    <img class="bt old_3" src="images/change_3.jpg" onclick="selvirtualinfo(1,<?php echo $list['id']?>)">
                </li>
				<?php }?>
            </div>	
        </div>
		<div id="changebox" style="z-index:10">
			<img class="bt" id="change_4" src="">	
			<strong><div id="describes" class="txt"></div><strong>
			<img class="bt" id="change_5" src="images/change_5.jpg">
            <script>
				document.getElementById("change_5").addEventListener("touchstart", touchStartchange_5, false);
				document.getElementById("change_5").addEventListener("touchend", touchEndchange_5, false);
				function touchStartchange_5(event){
					startX = event.touches[0].clientX;
					document.getElementById('change_5').src='images/change_5_h.jpg';	
				}
				function touchEndchange_5(event){
					endX = event.changedTouches[0].clientX;
					document.getElementById('change_5').src='images/change_5.jpg';
				}	
			</script>
			<span class="bt" id="coupons"><strong id="dhm"></strong></span>
			<span class="bt" id="coupons2"><strong id="mm"></strong></span>
		</div>
	</div>
</div>

<div class='pop_mask'style="display:none; width:100%;height:100%"></div>
<div class="userpop_body" style="display:none;" id="cancel_con1">
    <div class="userpop_body_inner">
        <div class="userpop_body_cancel"><a href="javascript:void(0)" class="cancel1"><img src="images/pop1_cancel.png" width="40" height="40" /></a></div>
        <div class="userpop_body_txt">
            <div class="userpop_body_txt1">好消息！！</div>
            <div class="userpop_body_txt3">"售油达标，更多积分"</div>
            <div class="userpop_body_txt2">感谢您的努力与付出，您所在门店的本月销量已达标，可获得额外积分奖励，奖励积分已发放至店长账户，请继续努力~</div>
            <div class="userpop_body_txt4">本活动最终解释权归壳牌所有</div>
        </div>
    </div>
</div>

<div class="userpop_body" style="display:none;" id="cancel_con2">
    <div class="userpop_body_inner">
        <div class="userpop_body_cancel"><a href="javascript:void(0)" class="cancel2"><img src="images/pop1_cancel.png" width="40" height="40" /></a></div>
        <div class="userpop_body_txt">
            <div class="userpop_body_txt1">系统维护通知</div>
            <div class="userpop_body_txt2">亲爱的用户您好，壳牌喜力汽车专家将于今晚21:00-24:00进入系统维护时间，期间将不能进行油品扫码、积分兑换等操作，对您造成的不便敬请谅解。</div>
            <!--<div class="userpop_body_txt3"><span>●</span>喜力HX7 - 10分</div>
            <div class="userpop_body_txt3"><span>●</span>喜力HX8 - 15分</div>
            <div class="userpop_body_txt3"><span>●</span>超凡喜力 - 20分</div>
            <div class="userpop_body_txt2">之后对于表现突出的门店，会给到店长额外的奖励，感谢大家的支持。</div>-->
        </div>
        <div class="userpop_body_btn"><a href="javascript:void(0)" class="cancel2">返回</a></div>
    </div>
</div>

<div class="userpop_body" style="display:none;" id="cancel_con3">
    <div class="userpop_body_inner">
        <div class="userpop_body_cancel"><a href="javascript:void(0)" class="cancel3"><img src="images/pop1_cancel.png" width="40" height="40" /></a></div>
        <div class="userpop_body_txt">
            <div class="userpop_body_txt1">红包活动</div>
            <div class="userpop_body_txt2">红包活动开始了，请点击菜单栏“积分验证”中的【积分红包】，领取红包即可获得随机积分！</div>
            <div class="userpop_body_txt4">本活动最终解释权归壳牌所有</div>
        </div>
    </div>
</div>

<script type="text/javascript">
$(document).ready(function() {
	//点击关闭查看心愿单
	$('#prompt_2').click(function(){
		$('#prompt').fadeOut(500);
	});
	
	//兑换记录 查看
	$('#change_7').click(function(){
		$('#old').fadeIn(500);
	});
	
	$('#old_4').click(function(){
		$('#old').fadeOut(500);
	});
	
	$('#sale_1').click(function(){
		$('#sale_1').attr('src','images/sale_1.png');	
		$('#change_1').attr('src','images/change_2.png');
		$('#sale').show();
		$('#change').hide();
	});
	$('#change_1').click(function(){
		$('#sale_1').attr('src','images/sale_2.png');	
		$('#change_1').attr('src','images/change_1.png');
		$('#change').show();
		$('#sale').hide();
	});
	
	$('#p4_2').click(function(){
		$('#rule').fadeIn(500);
	});
	$('#rule_1').click(function(){
		$('#rule').fadeOut(500);
	});
	
	$('#integral_1').click(function(){
		$('#integral').fadeOut(500);
	});

	$('#p4_3').click(function(){
		$('#p4box').fadeIn(500);
	});
	
	$('#change_5,#change_6').click(function(){
		$('#changebox').fadeOut(500);
	});

    setTimeout("popup()", 1000);

    $(".cancel1").click(function(){
        $(".pop_mask").fadeOut(500);
        $("#cancel_con1").fadeOut(500);
    });

    $(".cancel2").click(function(){
        $(".pop_mask").fadeOut(500);
        $("#cancel_con2").fadeOut(500);
    });

    $(".cancel3").click(function(){
        $(".pop_mask").fadeOut(500);
        $("#cancel_con3").fadeOut(500);
    });
});	

//查看兑奖记录
function selvirtualinfo(type,id){//type=1为新版本 2为旧版本
	$.ajax({
		type: "GET",
		url: "ra_ajax.php?selvirtualinfo=1&type="+type+"&id="+id,
		dataType:'json',
		success: function(data){
			if(data.result=='success'){
				if(data.type == 1){
					$('#describes').show();
					if(data.cardnum == ''){
						$('#dhm').html('您的兑换码：'+data.password);
						$('#mm').html('');
						$('#coupons').css({left:120/p+'px',top:460/p+'px',height:64/p+'px',fontSize:26/p+'px'});
					}else{
						$('#dhm').html('您的兑换码：'+data.cardnum);
						$('#mm').html('您的密码：'+data.password);
						$('#coupons').css({left:120/p+'px',top:435/p+'px',height:64/p+'px',fontSize:26/p+'px'});
						$('#coupons2').css({left:120/p+'px',top:485/p+'px',height:64/p+'px',fontSize:26/p+'px'});
					}
					$('#describes').html(data.describes);
					document.getElementById('change_4').src='images/change_4.png';
					$('#change_5').width(140/p).height(54/p).css({left:(x-140/p)/2+'px',top:880/p+'px'});
					$('#describes').width(480/p).height(200/p).css({left:125/p+'px',top:620/p+'px',fontSize:24/p+'px',lineHeight:35/p+'px'});
				}else{
					if(data.cardnum == ''){
						$('#dhm').html('您的哈根达斯券兑换码是：'+data.password);
						$('#mm').html('');
						document.getElementById('change_4').src='images/change_4_1.png';
						$('#coupons').css({left:100/p+'px',top:405/p+'px',height:64/p+'px',fontSize:26/p+'px'});
					}else{
						$('#describes').show();
						$('#dhm').html('您的兑换码：'+data.cardnum);
						$('#mm').html('您的密码：'+data.password);
						$('#describes').html(data.describes);
						document.getElementById('change_4').src='images/change_4.png';
						$('#coupons').css({left:120/p+'px',top:435/p+'px',height:64/p+'px',fontSize:26/p+'px'});
						$('#coupons2').css({left:120/p+'px',top:485/p+'px',height:64/p+'px',fontSize:26/p+'px'});
						$('#describes').width(480/p).height(200/p).css({left:125/p+'px',top:620/p+'px',fontSize:24/p+'px',lineHeight:35/p+'px'});
					}
					$('#change_5').width(140/p).height(54/p).css({left:(x-140/p)/2+'px',top:880/p+'px'});
				}
				$('#changebox').fadeIn(500);
			}
			getWidth();
		}
	});
}

//修改个人资料

//确认修改个人资料
	document.getElementById("p4boxbt").addEventListener("touchstart", touchStartp4boxbt, false);
	document.getElementById("p4boxbt").addEventListener("touchend", touchEndp4boxbt, false);
	function touchStartp4boxbt(event){
		startX = event.touches[0].clientX;
		document.getElementById('p4boxbt').src='images/p2boxbt_h.jpg';	
	}
	function touchEndp4boxbt(event){
		endX = event.changedTouches[0].clientX;
	 	document.getElementById('p4boxbt').src='images/p2boxbt.jpg';
	}
$('#p4boxbt').click(function(){
	if(check()){
		var id='<?php echo $user['id']?>';
		var name=$('#nm').val();
		var phone=$('#tel').val();
		var address=$('#add').val();
		$.ajax({
			type: "GET",
			url: "ra_ajax.php?update_user=1&id="+id+"&name="+name+"&phone="+phone+"&address="+address,
			success: function(data){
				if(data == 'success'){
					alert('修改成功');
					$('#p4text_1').html(name);
					$('#p4box').fadeOut(500);
				}
				getWidth();
			}
		});
	}
});
//取消修改个人资料
	document.getElementById("p4boxbt_2").addEventListener("touchstart", touchStartp4boxbt_2, false);
	document.getElementById("p4boxbt_2").addEventListener("touchend", touchEndp4boxbt_2, false);
	function touchStartp4boxbt_2(event){
		startX = event.touches[0].clientX;
		document.getElementById('p4boxbt_2').src='images/p2boxbt_2_h.jpg';	
	}
	function touchEndp4boxbt_2(event){
		endX = event.changedTouches[0].clientX;
	 	document.getElementById('p4boxbt_2').src='images/p2boxbt_2.jpg';
	}
$('#p4boxbt_2').click(function(){
	$('#p4box').fadeOut(500);
	$('#nm').val('<?php echo $user['name']?>');
	$('#tel').val('<?php echo $user['phone']?>');
	$('#add').val('<?php echo $user['address']?>');
});

function check(){
	if(trim(document.getElementById('nm').value)==''){
		alert('请输入姓名')
		return false;
	}
	
	var phone=document.getElementById('tel').value;
	var myregPhone = /^(13[0-9]|14[0-9]|15[0-9]|18[0-9])\d{8}$/i;
	if(trim(phone)==''){
		alert('请输入电话');
		return false;
	}else{
		if(!myregPhone.test(phone)){
			alert('请输入正确的电话号');
			return false;
		}
	}
	
	if(trim(document.getElementById('add').value)==''){
		alert('请输入地址');
		return false;
	}
	
	return true;
}

function getWidth(){
	$('#loadings').width(x).height(y).css({left:0,top:0});
	$('.p1,.p2,.p3,.p4,.container,.bg').width(x);
	$('.container').height(y);
	$('.p1,.p2,.p3,.p4,.p5,.p6,.p7,.p8').css({left:0,top:0});
	$('#prompt').width(x).height(65/p);
	$('#prompt_1').width(x).height(65/p);
	$('#prompt_2').width(30/p).height(32/p).css({right:20/p+'px',top:20/p+'px'});
	$('#prompt_3').css({left:360/p,top:17/p+'px',fontSize:30/p+'px'});
	//p2
	$('#p4text_1').css({left:53/p+'px',top:44/p+'px',fontSize:55/p+'px'});
	$('#p4text_2').css({left:53/p+'px',top:128/p+'px',fontSize:22/p+'px'});
	$('#p4text_3').css({left:71/p+'px',top:182/p+'px',fontSize:22/p+'px'});
	$('.oil').width(29/p).height(40/p);
	$('#oil_1').css({left:227/p+'px',top:119/p+'px'});
	$('#oil_2').css({left:261/p+'px',top:119/p+'px'});
	$('#oil_3').css({left:294/p+'px',top:119/p+'px'});
	$('#p4_1').width(157/p).height(53/p).css({left:56/p+'px',top:162/p+'px'});
	$('#p4_2').width(91/p).height(40/p).css({left:213/p+'px',top:175/p+'px'});
	$('#close').width(183/p).height(36/p).css({left:322/p+'px',top:178/p+'px'});
	$('#p4_3').width(120/p).height(120/p).css({right:0,top:0});
	$('.p4bt').width(165/p).height(165/p);
	$('#p4bt_1').css({left:64/p+'px',top:272/p+'px'});
	$('#p4bt_2').css({left:283/p+'px',top:272/p+'px'});
	$('#p4bt_3').css({left:502/p+'px',top:272/p+'px'});
	$('#p4bt_4').css({left:535/p+'px',top:405/p+'px',fontSize:20/p+'px'});
	$('#p4bt_4').width(100/p);
	$('#sale_1').width(360/p).height(67/p).css({left:0,top:482/p+'px'});
	$('#change_1').width(360/p).height(67/p).css({right:0,top:482/p+'px'});
	$('#sale,#change').width(x).height(620/p).css({left:0,top:550/p+'px'});
	$('#p4text_4').css({width:720/p+'px',height:99/p+'px',left:0,top:3/p+'px',fontSize:35/p+'px',lineHeight:99/p+'px'});
	$('#sale_3').width(x).height(55/p).css({left:0,top:130/p+'px'});
	$('#salebar').width(610/p).height(355/p).css({left:(x-610/p)/2+'px',top:190/p+'px'});
	$('#sale li').width(610/p).height(78/p);
	$('.saletext_1').css({left:22*3/4/p+'px',top:27/p+'px',fontSize:22/p+'px'});
	$('.saletext_2').css({left:213*3/4/p+'px',top:27/p+'px',fontSize:22/p+'px'});
	$('.saletext_3').css({left:534*3/4/p+'px',top:27/p+'px',fontSize:22/p+'px'});
    $('.saletext_1_new').css({left:22*3/4/p+'px',top:27/p+'px',fontSize:22/p+'px'});
    $('.saletext_2_new').css({left:213*3/4/p+'px',top:27/p+'px',fontSize:22/p+'px', width:'33%', 'text-overflow':'ellipsis', 'white-space':'nowrap', overflow:'hidden'});
    $('.saletext_3_new').css({left:534*3/4/p+'px',top:27/p+'px',fontSize:22/p+'px'});
    $('.saletext_4_new').css({left:680*3/4/p+'px',top:27/p+'px',fontSize:22/p+'px',width:100*3/4/p+'px'});
    $('.saletext_4_new').children('img').css({width:'100%',top:'-5px'});
	$('#change_3').width(x).height(55/p).css({left:0,top:<?php echo $_GET['source']=='user'?140:40?>/p+'px'});
	$('#change li').width(610/p).height(78/p);
	$('#changebar').width(610/p).height(350/p).css({left:(x-610/p)/2+'px',top:<?php echo $_GET['source']=='user'?195:95?>/p+'px'});
	$('.change_3').width(91/p).height(50/p).css({left:680*3/4/p+'px',top:12/p+'px'});
	$('#rule,#integral').width(x).height(y).css({left:0,top:0});
	$('#p4_2mb,#p4bt_3mb').width(x).css({left:0,top:0});
	$('#rule_1').width(140/p).height(54/p).css({left:(x-140/p)/2+'px',top:750/p+'px'});
	$('#integral_1').width(140/p).height(54/p).css({left:(x-140/p)/2+'px',top:688/p+'px'});
	$('#ruletext_1,#integraltext_1').css({width:507/p+'px',left:(x-507/p)/2+'px',top:438/p+'px',fontSize:28/p+'px',lineHeight:50/p+'px'});
	$('#ruletext_2,#integraltext_2').css({width:507/p+'px',left:(x-507/p)/2+'px',top:546/p+'px',fontSize:28/p+'px',lineHeight:50/p+'px'});
	$('#p4box').width(x).css({left:0,top:0});
	$('#p4boxbt,#p4boxbt_2').width(203/p).height(76/p);
	$('#p4boxbt').css({left:452/p+'px',top:1019/p+'px'});
	$('#p4boxbt_2').css({left:69/p+'px',top:1019/p+'px'});
	$('#nm').css({left:248/p+'px',top:273/p+'px',width:406/p+'px',height:64/p+'px',fontSize:24/p+'px'});
	$('#tel').css({left:248/p+'px',top:387/p+'px',width:406/p+'px',height:64/p+'px',fontSize:24/p+'px'});
	$('#add').css({left:248/p+'px',top:502/p+'px',width:406/p+'px',height:64/p+'px',fontSize:24/p+'px'});
	$('#shop_name').css({left:248/p+'px',top:616/p+'px',width:406/p+'px',lineHeight:64/p+'px',fontSize:24/p+'px',marginLeft:12/p+'px'});
	$('#change_4,#changebox').width(x).css({left:0,top:0});
	$('#change_7').width(x).height(99/p).css({marginTop:2/p+'px'});
	$('#old').width(x).css({left:0,top:0});
	$('#oldbar').width(606/p).height(840/p).css({left:(x-606/p)/2+'px',top:138/p+'px'});
	$('#oldbar li').css({width:606/p+'px',height:80/p+'px',fontSize:24/p+'px',lineHeight:60/p+'px'});
	$('.old_1').css({width:230/p+'px',height:80/p+'px',left:20/p+'px',fontSize:24/p+'px',lineHeight:80/p+'px'});
	$('.old_2').css({width:204/p+'px',height:80/p+'px',left:242/p+'px',fontSize:24/p+'px',lineHeight:80/p+'px'});
	$('.old_3').width(91/p).height(50/p).css({left:496/p+'px',top:15/p+'px'});
	$('#old_4').width(30/p).height(30/p).css({right:50/p+'px',top:50/p+'px'});
}

function popup() {
    // 如果是一号，并且上月销售达到奖励指标，则弹出奖励浮层，否则弹出售油积分规则浮层。
    var popupEncourage = false;
    var addscore = 0;
    var date = new Date();
    var today = date.getDate();
    var year = date.getFullYear();
    var month = date.getMonth() + 1;

    // 前一个月
    if (month == 1) {
        month = "12";
        year = year - 1;
    } else {
        month = month - 1;
    }

    if (month < 10) {
        month = "0" + month;
    }

    if (today == 1 || today == 2 || today == 3 || today == 4 || today == 5) {
        $.ajax({
            type: "GET",
            url: "ra_ajax_encourage.php",
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            async:false,
            data: {method:"checkpopup", shopid:$("#shopid").val(), userid:$("#userid").val(),  year:year, month:month},
            success: function (data) {
                if (data.status == 1) {
                    popupEncourage = true;
                    addscore = data.addscore;
                } else {
                    popupEncourage=false;
                }
            }
        });
    }

    if (popupEncourage) {
        var popupWidth =  $(".container").width();
        var windowWidth =  $(window).outerWidth();
        var windowHeight =  $(window).outerHeight();
        var popupHeight = $("#cancel_con1").height();
        $(".pop_mask").fadeIn(500);
        $("#cancel_con1").css({"position": "absolute", "width":popupWidth+"px"}).animate({left: windowWidth/2-popupWidth/2, top: windowHeight/2-popupHeight/2, opacity: "show" }, "slow");
        return;
    }
	//普通活动浮层通知  注释开启或者关闭
    else {
        var popupWidth =  $(".container").width();
        var windowWidth =  $(window).outerWidth();
        var windowHeight =  $(window).outerHeight();
        var popupHeight = $("#cancel_con2").height();
        $(".pop_mask").fadeIn(500);
       $("#cancel_con2").css({"position": "absolute", "width":popupWidth+"px"}).animate({left: windowWidth/2-popupWidth/2, top: windowHeight/2-popupHeight/2, opacity: "show" }, "slow");
    }

    // 红包浮层判断
    $.ajax({
        type: "GET",
        url: "ra_ajax_redpocket.php",
        dataType: "json",
        contentType: "application/json; charset=utf-8",
        async:false,
        data: {method:"checkpopup", userid:$("#userid").val()},
        success: function (data) {
            if (data.status == 1) {
                var popupWidth =  $(".container").width();
                var windowWidth =  $(window).outerWidth();
                var windowHeight =  $(window).outerHeight();
                var popupHeight = $("#cancel_con3").height();
                $(".pop_mask").fadeIn(500);
                $("#cancel_con3").css({"position": "absolute", "width":popupWidth+"px"}).animate({left: windowWidth/2-popupWidth/2, top: windowHeight/2-popupHeight/2, opacity: "show" }, "slow");
                return;
            }
        }
    });
}

</script>
</body>
</html>